var express = require('express');
var session = require('express-session');
var path = require('path');
var router = express.Router();
var sqlite3 = require('sqlite3').verbose();

/* GET users listing. */
router.get('/', function (req, res, next) {
  var db = new sqlite3.Database(path.join(__dirname, "../db/data.s3db"));
  var redata = {};
  var mode = req.query.mode;
  if (mode == '1') { //查询本期
    sqlStr = "SELECT * from bill where thisTerm=='1'";
    db.all(sqlStr, function (err, rows) {
      redata.count = rows.length;
      redata.code = '0';
      redata.data = rows;
      res.send(redata);
    });
  } else if (mode == '2') { //查询往期
    sqlStr = "SELECT * from bill";
    db.all(sqlStr, function (err, rows) {
      redata.count = rows.length;
      redata.code = '0';
      redata.data = rows;
      res.send(redata);
    });
  } else if (mode == '3') { //查询往期
    sqlStr = "SELECT * from bill2";
    db.all(sqlStr, function (err, rows) {
      redata.count = rows.length;
      redata.code = '0';
      redata.data = rows;
      res.send(redata);
    });
  }


});

module.exports = router;